package com.example.delivery.controller;

import com.example.delivery.pojo.Review;
import com.example.delivery.service.ReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/review")
public class ReviewController {

    @Autowired
    private ReviewService reviewService;

    /**
     * 根据餐馆id查询所有评价
     * @param restaurantId
     * @return
     */
    @GetMapping("/all")
    @ResponseBody
    public Map<String, Object> all(@RequestParam Integer restaurantId) {
        Map<String,Object> map= new HashMap();
        try{
            List<Review> reviewList = reviewService.findAll(restaurantId);
            map.put("success",true);
            map.put("reviews",reviewList);
        }catch (Exception e) {
            map.put("success",false);
            map.put("message",e.getMessage());
        }
        return map;
    }
}
